<template>
  <view class="container">
    <van-sticky>
      <van-nav-bar
        :placeholder="true"
        title="扫码"
        left-arrow
        @click-left="back"
      >
      </van-nav-bar>
    </van-sticky>
    <mumu-get-qrcode
      @success="qrcodeSucess"
      @error="qrcodeError"
      :continue="false"
    >
      <template v-slot:error>
        <view>摄像头启动失败</view>
      </template>
    </mumu-get-qrcode>
  </view>
</template>

<script>
import mumuGetQrcode from "@/uni_modules/mumu-getQrcode/components/mumu-getQrcode/mumu-getQrcode.vue"; //引入
export default {
  components: {
    mumuGetQrcode,
  },
  data() {
    return {
      url: "",
    };
  },
  onLoad({ url }) {
    this.url = url;
  },
  name: "Qrcode",
  methods: {
    qrcodeSucess(data) {
      uni.$emit("scancode", data);
      uni.navigateBack();
      //   uni.showModal({
      //     title: "扫码成功",
      //     content: `设备编码：${data}`,
      //     success: () => {},
      //   });
    },
    qrcodeError(err) {
      //摄像头扫码失败返回
      uni.showModal({
        title: "摄像头授权失败",
        content: "摄像头授权失败，请检测当前浏览器是否有摄像头权限。",
        success: () => {
          uni.navigateBack({});
        },
      });
    },
    back() {
      history.back();
    },
  },
};
</script>

<style scoped lang="scss">
.container {
  height: 100%;
}
</style>
